package com.study.servlet;

import com.study.dao.CustomerDao;
import com.study.dao.impl.CustomerDaoImpl;
import com.study.model.Customer;
import com.study.util.GsonHelper;
import com.study.util.PageHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author WS
 */
@WebServlet(name = "updateCustomer",urlPatterns = "/updateCustomer")
public class CustomerUpdateServlet extends BaseServlet {
    private CustomerDao dao=new CustomerDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 解决json中文乱码
        req.setCharacterEncoding("UTF-8");
        Customer query=new Customer();
        String idstr=req.getParameter("id");
        System.out.println(idstr);
        int id=Integer.parseInt(idstr);
        Customer customer=dao.findById(id);
        req.setAttribute("UpdateCustomer",customer);
        req.getRequestDispatcher("/CustomerUpdate.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req,resp);
        doGet(req, resp);
    }
}
